﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Xml.Serialization;

namespace GFC
{
    [Serializable]
    [XmlInclude(typeof (PersistentFrame))]
    [XmlInclude(typeof (FieldDependantFrame))]
    [XmlInclude(typeof (FrameDependantFrame))]
    public abstract class Frame
    {
        protected List<Field> m_Fields;
        protected Format m_Format;
        protected string m_Name;

        protected Frame()
        {
            this.Fields = new List<Field>();
        }

        public Frame(string name, Format format)
        {
            this.m_Name = name;
            this.m_Fields = new List<Field>();
            this.m_Format = format;
        }

        [XmlIgnore]
        public Format Format
        {
            get { return m_Format; }
            set { m_Format = value; }
        }

        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        public List<Field> Fields
        {
            get { return m_Fields; }
            set { m_Fields = value; }
        }

        public override bool Equals(object obj)
        {
            var frame = obj as Frame;
            if (frame == null)
                return false;
            if (Fields.Count != frame.Fields.Count)
                return false;
            for (int i = 0; i < Fields.Count; i++)
            {
                if (!Fields[i].Equals(frame.Fields[i]) || Fields[i].Frame != this || frame.Fields[i].Frame != frame)
                    return false;
            }
            return true;
        }
    }
}